<?xml version="1.0" encoding="UTF-8"?>
 
 <xs:schema 
  xmlns:xs="http://www.w3.org/2001/XMLSchema" 
  xmlns:xml="http://www.w3.org/XML/1998/namespace"
  xmlns="http://www.w3.org/2007/rif#"
  targetNamespace="http://www.w3.org/2007/rif#"
  elementFormDefault="qualified"
  version="Id: BLDCond.xsd, v. 1.6, 2010-05-08, dhirtle/hboley">

 <xs:import namespace='http://www.w3.org/XML/1998/namespace'
            schemaLocation='http://www.w3.org/2001/xml.xsd'/> 
 
  <xs:annotation>
    <xs:documentation>
    This is the XML schema for the Condition Language as defined by
    the Last Call Draft of the RIF Basic Logic Dialect.
    
    The schema is based on the following EBNF for the RIF-BLD Condition Language:
 
  FORMULA        ::= IRIMETA? 'And' '(' FORMULA* ')' |
                     IRIMETA? 'Or' '(' FORMULA* ')' |
                     IRIMETA? 'Exists' Var+ '(' FORMULA ')' |
                     ATOMIC |
                     IRIMETA? 'External' '(' Atom ')'
  ATOMIC         ::= IRIMETA? (Atom | Equal | Member | Subclass | Frame)
  Atom           ::= UNITERM
  UNITERM        ::= Const '(' (TERM* | (Name '->' TERM)*) ')'
  Equal          ::= TERM '=' TERM
  Member         ::= TERM '#' TERM
  Subclass       ::= TERM '##' TERM
  Frame          ::= TERM '[' (TERM '->' TERM)* ']'
  TERM           ::= IRIMETA? (Const | Var | Expr | List | 'External' '(' Expr ')')
  Expr           ::= UNITERM
  List           ::= 'List' '(' TERM* ')' | 'List' '(' TERM+ '|' TERM ')'
  Const          ::= '"' UNICODESTRING '"^^' SYMSPACE | CONSTSHORT
  Var            ::= '?' Name
  Name           ::= NCName | '"' UNICODESTRING '"'
  SYMSPACE       ::= ANGLEBRACKIRI | CURIE
 
  IRIMETA        ::= '(*' IRICONST? (Frame | 'And' '(' Frame* ')')? '*)'
 
    </xs:documentation>
  </xs:annotation>
  
  <xs:group name="FORMULA">  
    <!--
  FORMULA        ::= IRIMETA? 'And' '(' FORMULA* ')' |
                     IRIMETA? 'Or' '(' FORMULA* ')' |
                     IRIMETA? 'Exists' Var+ '(' FORMULA ')' |
                     ATOMIC |
                     IRIMETA? 'External' '(' Atom ')'
    -->
    <xs:choice>
      <xs:element ref="And"/>
      <xs:element ref="Or"/>
      <xs:element ref="Exists"/>
      <xs:group ref="ATOMIC"/>
      <xs:element name="External" type="External-FORMULA.type"/>
    </xs:choice>
  </xs:group>
  
  <xs:complexType name="External-FORMULA.type">
    <!-- sensitive to FORMULA (Atom) context-->
    <xs:sequence>
      <xs:group ref="IRIMETA" minOccurs="0" maxOccurs="1"/>
      <xs:element name="content" type="content-FORMULA.type"/>
    </xs:sequence>
  </xs:complexType>
  
  <xs:complexType name="content-FORMULA.type">
    <!-- sensitive to FORMULA (Atom) context-->
    <xs:sequence>
      <xs:element ref="Atom"/>
    </xs:sequence>
  </xs:complexType>
 
  <xs:element name="And">
    <xs:complexType>
      <xs:sequence>
        <xs:group ref="IRIMETA" minOccurs="0" maxOccurs="1"/>
        <xs:element ref="formula" minOccurs="0" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  
  <xs:element name="Or">
    <xs:complexType>
      <xs:sequence>
        <xs:group ref="IRIMETA" minOccurs="0" maxOccurs="1"/>
        <xs:element ref="formula" minOccurs="0" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  
  <xs:element name="Exists">
    <xs:complexType>
      <xs:sequence>
        <xs:group ref="IRIMETA" minOccurs="0" maxOccurs="1"/>
        <xs:element ref="declare" minOccurs="1" maxOccurs="unbounded"/>
        <xs:element ref="formula"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  
  <xs:element name="formula">
    <xs:complexType>
      <xs:sequence>
        <xs:group ref="FORMULA"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  
  <xs:element name="declare">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="Var"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
 
  <xs:group name="ATOMIC">
    <!--
  ATOMIC         ::= IRIMETA? (Atom | Equal | Member | Subclass | Frame)
    -->
    <xs:choice>
      <xs:element ref="Atom"/>
      <xs:element ref="Equal"/>
      <xs:element ref="Member"/>
      <xs:element ref="Subclass"/>
      <xs:element ref="Frame"/>
    </xs:choice>
  </xs:group>
  
  <xs:element name="Atom">
    <!--
  Atom           ::= UNITERM
    -->
    <xs:complexType>
      <xs:sequence>
        <xs:group ref="UNITERM"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>  
  
  <xs:group name="UNITERM">
    <!--
  UNITERM        ::= Const '(' (TERM* | (Name '->' TERM)*) ')'
    -->
    <xs:sequence>
      <xs:group ref="IRIMETA" minOccurs="0" maxOccurs="1"/>
      <xs:element ref="op"/>
      <xs:choice>
        <xs:element ref="args" minOccurs="0" maxOccurs="1"/>
        <xs:element name="slot" type="slot-UNITERM.type" minOccurs="0" maxOccurs="unbounded"/>
      </xs:choice>
    </xs:sequence>
  </xs:group>
 
  <xs:element name="op">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="Const"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  
  <xs:element name="args">
    <xs:complexType>
      <xs:sequence>
        <xs:group ref="TERM" minOccurs="1" maxOccurs="unbounded"/>
      </xs:sequence>
      <xs:attribute name="ordered" type="xs:string" fixed="yes"/>
    </xs:complexType>
  </xs:element>
 
  <xs:complexType name="slot-UNITERM.type">
    <!-- sensitive to UNITERM (Name) context-->
    <xs:sequence>
      <xs:element ref="Name"/>
      <xs:group ref="TERM"/>
    </xs:sequence>
    <xs:attribute name="ordered" type="xs:string" fixed="yes"/>
  </xs:complexType>
 
  <xs:element name="Equal">
    <!--
  Equal          ::= TERM '=' TERM
    -->
    <xs:complexType>
      <xs:sequence>
        <xs:group ref="IRIMETA" minOccurs="0" maxOccurs="1"/>
        <xs:element ref="left"/>
        <xs:element ref="right"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
 
  <xs:element name="left">
    <xs:complexType>
      <xs:sequence>
        <xs:group ref="TERM"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
 
  <xs:element name="right">
    <xs:complexType>
      <xs:sequence>
        <xs:group ref="TERM"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
 
  <xs:element name="Member">
    <!--
  Member         ::= TERM '#' TERM
    -->
    <xs:complexType>
      <xs:sequence>
        <xs:group ref="IRIMETA" minOccurs="0" maxOccurs="1"/>
        <xs:element ref="instance"/>
        <xs:element ref="class"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
 
  <xs:element name="Subclass">
    <!--
  Subclass       ::= TERM '##' TERM
    -->
    <xs:complexType>
      <xs:sequence>
        <xs:group ref="IRIMETA" minOccurs="0" maxOccurs="1"/>
        <xs:element ref="sub"/>
        <xs:element ref="super"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  
  <xs:element name="instance">
    <xs:complexType>
      <xs:sequence>
        <xs:group ref="TERM"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  
  <xs:element name="class">
    <xs:complexType>
      <xs:sequence>
        <xs:group ref="TERM"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  
  <xs:element name="sub">
    <xs:complexType>
      <xs:sequence>
        <xs:group ref="TERM"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  
  <xs:element name="super">
    <xs:complexType>
      <xs:sequence>
        <xs:group ref="TERM"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
    
  <xs:element name="Frame">
    <!--
  Frame          ::= TERM '[' (TERM '->' TERM)* ']'
    -->
    <xs:complexType>
      <xs:sequence>
        <xs:group ref="IRIMETA" minOccurs="0" maxOccurs="1"/>
        <xs:element ref="object"/>
        <xs:element name="slot" type="slot-Frame.type" minOccurs="0" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
 
  <xs:element name="object">
    <xs:complexType>
      <xs:sequence>
        <xs:group ref="TERM"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
 
  <xs:complexType name="slot-Frame.type">
    <!-- sensitive to Frame (TERM) context-->
    <xs:sequence>
      <xs:group ref="TERM"/>
      <xs:group ref="TERM"/>
    </xs:sequence>
    <xs:attribute name="ordered" type="xs:string" fixed="yes"/>
  </xs:complexType>
 
  <xs:group name="TERM">  
    <!--
  TERM           ::= IRIMETA? (Const | Var | Expr | List | 'External' '(' Expr ')')
    -->
      <xs:choice>
         <xs:element ref="Const"/>
         <xs:element ref="Var"/>
         <xs:element ref="Expr"/>
         <xs:element ref="List"/>
         <xs:element name="External" type="External-TERM.type"/>
      </xs:choice>
  </xs:group>

  <xs:element name="List">  
    <!--
  List           ::= 'List' '(' TERM* ')' | 'List' '(' TERM+ '|' TERM ')'
             rewritten as
  List           ::= 'List' '(' LISTELEMENTS? ')'
    -->
    <xs:complexType>
      <xs:sequence>
        <xs:group ref="IRIMETA" minOccurs="0" maxOccurs="1"/>
        <xs:group ref="LISTELEMENTS" minOccurs="0" maxOccurs="1"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:group name="LISTELEMENTS">
    <!--
  LISTELEMENTS   ::= TERM+ ('|' TERM)?
    -->
    <xs:sequence>
      <xs:element ref="items"/>
      <xs:element ref="rest" minOccurs="0" maxOccurs="1"/>
    </xs:sequence>
  </xs:group>
  
  <xs:element name="items">
    <xs:complexType>
      <xs:sequence>
        <xs:group ref="TERM" minOccurs="1" maxOccurs="unbounded"/>
      </xs:sequence>
      <xs:attribute name="ordered" type="xs:string" fixed="yes"/>
    </xs:complexType>
  </xs:element>

  <xs:element name="rest">
    <xs:complexType>
      <xs:sequence>
        <xs:group ref="TERM"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  
  <xs:complexType name="External-TERM.type">
    <!-- sensitive to TERM (Expr) context-->
    <xs:sequence>
      <xs:group ref="IRIMETA" minOccurs="0" maxOccurs="1"/>
      <xs:element name="content" type="content-TERM.type"/>
    </xs:sequence>
  </xs:complexType>
  
  <xs:complexType name="content-TERM.type">
    <!-- sensitive to TERM (Expr) context-->
    <xs:sequence>
      <xs:element ref="Expr"/>
    </xs:sequence>
  </xs:complexType>
 
  <xs:element name="Expr">
    <!--
  Expr           ::= UNITERM
    -->
    <xs:complexType>
      <xs:sequence>
        <xs:group ref="UNITERM"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
 
  <xs:element name="Const">
    <!--
  Const          ::= '"' UNICODESTRING '"^^' SYMSPACE | CONSTSHORT
    -->
    <xs:complexType mixed="true">
      <xs:sequence>
        <xs:group ref="IRIMETA" minOccurs="0" maxOccurs="1"/>
      </xs:sequence>
      <xs:attribute name="type" type="xs:anyURI" use="required"/> 
      <xs:attribute ref="xml:lang"/>
    </xs:complexType>
  </xs:element>
  
  <xs:element name="Name" type="xs:string">
    <!--
  Name           ::= NCName | '"' UNICODESTRING '"'   
  ... i.e., 'Name' stands for either the NCName string or the UNICODESTRING with the outer quotes stripped off.
    -->
  </xs:element>
 
  <xs:element name="Var">
    <!--
  Var            ::= '?' Name
    -->
    <xs:complexType mixed="true">
      <xs:sequence>
        <xs:group ref="IRIMETA" minOccurs="0" maxOccurs="1"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
 
  <xs:group name="IRIMETA">
    <!--
  IRIMETA   ::= '(*' IRICONST? (Frame | 'And' '(' Frame* ')')? '*)'
    -->
    <xs:sequence>
      <xs:element ref="id" minOccurs="0" maxOccurs="1"/>
      <xs:element ref="meta" minOccurs="0" maxOccurs="1"/>
    </xs:sequence>
  </xs:group>
 
  <xs:element name="id">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Const" type="IRICONST.type"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
 
  <xs:element name="meta">
    <xs:complexType>
     <xs:choice>
       <xs:element ref="Frame"/>
       <xs:element name="And" type="And-meta.type"/>
     </xs:choice>
    </xs:complexType>
  </xs:element>
  
  <xs:complexType name="And-meta.type">
  <!-- sensitive to meta (Frame) context-->
    <xs:sequence>
      <xs:element name="formula" type="formula-meta.type" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>
 
  <xs:complexType name="formula-meta.type">
    <!-- sensitive to meta (Frame) context-->
    <xs:sequence>
      <xs:element ref="Frame"/>
    </xs:sequence>
  </xs:complexType>
  
  <xs:complexType name="IRICONST.type" mixed="true">
    <!-- sensitive to location/id context-->
    <xs:sequence/>
    <xs:attribute name="type" type="xs:anyURI" use="required" fixed="http://www.w3.org/2007/rif#iri"/>
  </xs:complexType>
  
 </xs:schema>
